   //查看订单备注
   function initSeeOrderInfo(){
	   $('.SeeInfo').live('click', function () {
			$('#ShowreturnInfo').empty(); 
		var obj = JSON.parse($(this).attr("info")); 
		var info=obj.returned_goods_info;
		if(info!=null)
		for(var i=0;i<info.length;i++){
		$('#ShowreturnInfo').append("<span style=' margin:0'>"+info[i].time+":</span><br>"+"<span style=' margin:0'>"+info[i].title+":</span><br>"+"<p style=' margin:0'>  "+info[i].info+"</p>");
		}
			$('#Info-form').dialog('open'); 
			
 			 }
		);
	   }
      //查看订单路线
   function initSeeOrderPath(){
	   $('.SeePath').live('click', function () {
		var pathID=$(this).attr("Path"); 
			$('#Path-form').dialog('open'); 
			findOrderPath(pathID);
			});
	   
	   $('.ShowSeePath').live('click', function () {
			$('#ShowPath-form').dialog('open'); 
			$('#ShowOrderPath').empty(); 
		var json = JSON.parse($(this).attr("Path")); 
		var end=json.endAddr;
		var paths=json.path;
		if(end!=null){
		$('#ShowOrderPath').append("<p style=' margin:0'>目的地:</p>");
		$('#ShowOrderPath').append("<p style=' margin:0'>"+end+"</p>");
		}
				
				if(paths!=null){
		for(var i=0;i<paths.length;i++){
			var time=paths[i].time;
			var addr=paths[i].addr;
			$('#ShowOrderPath').append("<p style=' margin:0'>"+time+":</p>");
			$('#ShowOrderPath').append("<p style=' margin:0'>"+addr+"</p>");
			}
				}
			});
	   }
   
   //初始化订单一级表格
   function initOrderJqgrid(){
	   initPathform();
	   iniPath();
	   initFind_Orderdatepicker();
	   initSeeOrderInfo();
	   initSeeOrderPath();
		initreturnInfo();
		initShowreturnInfo();
		$( "button").button();
     $("#list1").jqGrid({
   	url:'../orderHandle/queryMainOrder.jsp',
	datatype: "xml",
   	colNames:['订单ID','订单总交易额','用户支付金额','订单添加时间','客户ID','送货员ID' , '送货路线','订单状态','备注'],
   	colModel:[
		{name:'Order_ID', width:100, sortable:false},
   		{name:'Order_Total_Price',index:'Order_Total_Price', width:75},
		{name:'Payment_Price',index:'Payment_Price',editable:true, width:75},
   		{name:'Order_AddTime',index:'Order_AddTime', width:100},
		{name:'User_ID', width:75,sortable:false},
		{name:'Deliver_ID', width:75, align:"right",sortable:false},
   		{name:'Deliver_Path_ID', width:50,sortable:false,formatter:Fmatter_Order_Path},
   		{name:'Order_Status', width:80, align:"right",sortable:false,formatter:Fmatter_Order_Status},	
		{name:'Info', width:80, align:"right",sortable:false,formatter:Fmatter_Order_Info},	
   	],
	//scroll: true,
   	rowNum:5,
   	autowidth: true,
	height:400,
   	rowList:[10,20,30],
	prmNames:{page:'page',rows:'rows',order: 'sord', search:'_search', nd:'nd', npage:null},
	postData:{page:'page',rows:'rows', sort: 'sidx',order: 'sordsdf'},
   	pager: jQuery('#pager1'),
	loadCompele: $( "button").button(),
	loadError:   function(xhr,stu,e){alert(xhr.responseText);},
   	sortname: 'Order_ID',
    viewrecords: true,
    sortorder: "desc",
    caption:"XML Example",	
	forceFit : true, 
	cellEdit: true,
	cellsubmit: 'clientArray',
	afterEditCell: function (id,name,val,iRow,iCol){
		
	},
	afterSaveCell : function(rowid,name,val,iRow,iCol) {
		
	},
	
	onSelectRow: function(id){    
      
   },   
	gridComplete: function() {
    	$( "button").button();
    }, 
	//此事件在点击表格特定单元格时发生。rowid 为行ID；iCol 为列索引；cellcontent 为单元格中内容；e 点击事件对象
	onCellSelect:function(rowid,iCol,cellcontent,e){
		if(iCol==7){
			//alert($(cellcontent).text());
			var myrow = jQuery('#list1').jqGrid('getRowData',rowid);
			if($(cellcontent).text()=='发货'){
				var aa= window.confirm("是否确认发货？");
				if (aa) {
					delivery(myrow.Order_ID);
				}
				}else if($(cellcontent).text()=='确认收货'){
				var aa= window.confirm("是否确认收货？");
				if (aa) {
					Receiving(myrow.Order_ID,myrow.User_ID);
				}
					
				}else if($(cellcontent).text()=='退货'){
					
					$('#returnGoods-form').dialog('open').children('form')[0].reset();  
					$("#returnGoods_Order_ID").text(myrow.Order_ID);
					$("#returnGoods_User_ID").text(myrow.User_ID);
					
				}
			//delUser(myrow.User_ID);
			}
		},
	editurl:"../userHandle/editUser.jsp",
	subGrid : true,
     subGridRowExpanded: function (subgrid_id, row_id){SubGridOrder(subgrid_id, row_id) },
         
}).navGrid('#pager1',{edit:false,add:false,del:false,search: false });	
//jQuery("#list1").jqGrid('inlineNav',"#pager1");
	   }
	   //通过订单表的行ID获取订单ID
	   function getOrder_ID_By_Row(rowid){
		   var myrow = jQuery('#list1').jqGrid('getRowData',rowid);
			return myrow.Order_ID;
		   }
	   
	   //订单表格的二级表格初始化
	   function SubGridOrder(subgrid_id, row_id){    
	  var Order_ID= getOrder_ID_By_Row(row_id);
	  //alert("subgrid_id="+subgrid_id+" row_id="+row_id+" Order_ID="+Order_ID);
         var subgrid_table_id; 
		 pager_id = "p_"+subgrid_table_id;
         jQuery("#"+subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
         jQuery("#"+subgrid_table_id).jqGrid({      
            url: '../orderHandle/queryProductOrder.jsp?Order_ID='+Order_ID, //获取数据
            datatype: "xml", 
			viewrecords: true,
			pager:jQuery("#"+pager_id),
            mtype: 'POST',
            colNames: ['产品ID','产品名称','产品销售价格','购买产品数量','产品销售总额'], 
            colModel: [ 
             {name:"Order_Products", width:100,sortable:false}, 
             {name:"Product_Name",width:130, sortable:false}, 
             {name:"Product_Sale_Price",width:80,align:"left", sortable:false}, 
             {name:"Product_Num",width:80,align:"right",sortable:false},
			 {name:"Order_Total_Price",width:80,align:"right",sortable:false} 
              ], 
            rowNum: 20, 
            imgpath: 'images图片URL', 
            sortname: 'Order_Products', 
            sortorder: "asc" });
		   }
	 //格式话产品状态类型
	function Fmatter_Order_Status(cellvalue, options, rowObject){
		  if(cellvalue=='0'){
			  return "未下单";
		  }else if(cellvalue=='1'){
			  return "已下单";
		  }else if(cellvalue=='2'){
			  return "<button >发货</button>";
		  }else if(cellvalue=='3'){
			  return "<button >确认收货</button><button >退货</button>";
		  }else if(cellvalue=='4'){
			  return "已送货";
		  }else if(cellvalue=='5'){
			  return "已退货";
		  }
		}
		 //格式话产品状态类型
	function Fmatter_Order_Info(cellvalue, options, rowObject){
		
		return "<button class='SeeInfo' info='"+cellvalue+"'>查看留言</button>"
		}	
		
			 //格式话产品状态类型
	function Fmatter_Order_Path(cellvalue, options, rowObject){
		
		return "<button class='SeePath' Path='"+cellvalue+"'>查看路径</button>"
		}
		
				 //格式话产品状态类型
	function Fmatter_ShowOrder_Path(cellvalue, options, rowObject){
		
		return "<button class='ShowSeePath' Path='"+cellvalue+"'>查看路线</button>"
		}
		
		//格式化表格删除按键
	function FmatterDel(cellvalue, options, rowObject){
			return "删除";
		}

 //添加用户提示
 function AddUserMsg(text){
/*	 $( ".Add_User_Msg" ).text( text )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				$( ".Add_User_Msg" ).removeClass( "ui-state-highlight", 1500 );
			}, 500 )*/;
			Toalert(text);
	 }
 function Toalert(text){
	 alert(text);
	 }
	 
//初始化搜索订单添加时间
function initFind_Orderdatepicker(){
			var dates = $( "#Start_Order_AddTime, #End_Order_AddTime" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "Start_Order_AddTime" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	}
	
//初始化查询订单，指定送货按钮 
function initfindOrder(){
			$("#find").click(
		    function(){
				//alert($("#search").serialize());
	 findOrder();
			}
		);	
			$("#Find_Deliver_Button").click(
		    function(){
				//alert($("#search").serialize());
	 findDeliver();
			}
		)
	}
	//搜索用户事件
	function findOrder(){
		/*获取select 选中的 text : 
	$("#ddlRegType").find("option:selected").text(); 
	获取select选中的 value: 
	$("#ddlRegType ").val(); 
	获取select选中的索引: 
	$("#ddlRegType ").get(0).selectedIndex; 
	设置select: 
	设置select 选中的索引： 
	$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值*/
	//alert("userid="+$( "#userid").val()+"  username="+$( "#username").val()+"  usertype="+$( 			"#usertype").get(0).selectedIndex);
	var OrderID=$( "#OrderID").val();
	var OrderName=$( "#OrderName").val();
	var OrderStatus=$( "#OrderStatus").val();
	var StartAddTime=$( "#Start_Order_AddTime").val();
	var EndAddTime=$( "#End_Order_AddTime").val();
$("#list1").jqGrid('setGridParam',{ url: '../orderHandle/queryMainOrder.jsp',
postData:{Order_ID:OrderID,Order_Name:OrderName,Order_Status:OrderStatus,Start_AddTime:StartAddTime,End_AddTime:EndAddTime},
}).trigger('reloadGrid'); 
		}
//发货
function delivery(Order_ID){
		var data="Order_ID="+Order_ID;
		sendMsg("../orderHandle/Sure_Delivery.jsp",data);
	}
//确认收货
function Receiving(Order_ID,User_ID){
	var data="Order_ID="+Order_ID+"&User_ID="+encodeURIComponent(User_ID);
	sendMsg("../orderHandle/Sure_Receiving.jsp",data);
	}
//退货
function returned_goods(Order_ID,User_ID,Info){
	var data="Order_ID="+Order_ID+"&User_ID="+encodeURIComponent(User_ID)+"&Info="+encodeURIComponent(Info);
	sendMsg("../orderHandle/returned_goods.jsp",data);
	}
	
function initShowreturnInfo(){
	$( "#Info-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
		
			"取消": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				$('#Info-form').dialog('close'); 
			}
			}
		});
	}
	//查询订单路线
	function findOrderPath(Path_ID){
$("#AddOrderPathPathID").text(Path_ID);
$("#Path_list1").jqGrid('setGridParam',{ url: '../deliverpathHandle/queryDeliverpath.jsp',
postData:{Path_ID:encodeURIComponent(Path_ID)}
}).trigger('reloadGrid'); 
		}
	
function initPathform(){
	$( "#Path-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 850,
			modal: true,
			buttons: {
		
			"返回": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				$('#Path-form').dialog('close'); 
			}
			}
		});
	

	
	$( "#ShowPath-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 550,
			modal: true,
			buttons: {
			"新增路线": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				$('#AddPath-form').dialog('open'); 
				$('#ShowPath-form').dialog('close'); 
				$('#Path-form').dialog('close'); 
			},
			"返回": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				$('#ShowPath-form').dialog('close'); 
			}
			}
		});
	
		$( "#AddPath-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 550,
			modal: true,
			buttons: {
			"添加": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				var PathID=$("#AddOrderPathPathID").text();
				var path=$("#AddPath").val();
						$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url:"../deliverpathHandle/addPathToDeliver.jsp",
   data: encodeURI("Path_ID="+PathID+"&addr="+path),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		$("#list1").trigger("reloadGrid");
		AddUserMsg($(xmlResponse).find('msg').text());
		
		}else{
		AddUserMsg($(xmlResponse).find('msg').text());
		}
 	},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
     alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
			},
			"返回": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
				$('#AddPath-form').dialog('close'); 
			}
			}
		});
	}	
	
	//初始化送货员表格
   function iniPath(){
     $("#Path_list1").jqGrid({
   	url:'../deliverpathHandle/queryDeliverpath.jsp',
	datatype: "xml",
   	colNames:['路线ID','订单ID','路线','送货路程','运输费用','备注'],
   	colModel:[
		{name:'Path_ID', width:120, sortable:false},
		{name:'Order_ID', width:120, sortable:false},
		{name:'Path_Addrs', width:120, sortable:false, formatter:Fmatter_ShowOrder_Path},
   		{name:'Distance',index:'Distance',editable:true, width:100 },
		{name:'Transport_Cost',editable:true, width:75},
		{name:'Info', width:75,editable:true,sortable:false},
   	],
	//scroll: true,
   	rowNum:10,
   	autowidth: true,
	height:100,
   	rowList:[10,20,30],
	prmNames:{page:'page',rows:'rows',order: 'sord', search:'_search', nd:'nd', npage:null},
	//postData:{page:'page',rows:'rows', sort: 'sidx',order: 'sordsdf'},
   	pager: jQuery('#Path_pager1'),
   	sortname: 'ID',
    viewrecords: true,
    sortorder: "desc",
    caption:"指定送货员",	
	forceFit : true,
	cellEdit: true,
	cellsubmit: 'clientArray',
	afterEditCell: function (id,name,val,iRow,iCol){
	
	},
	afterSaveCell : function(rowid,name,val,iRow,iCol) {
		var myrow = jQuery('#Path_list1').jqGrid('getRowData',rowid);
		modifyPath(myrow.Path_ID,myrow.Order_ID,name+"="+val);
	},
	loadCompele:function(){alert("compele")},
	loadError:function(){alert("error")},
	onSelectRow: function(id){    
      
   },   
	gridComplete: function() {
    	//$( "button").button();
    }, 
	//此事件在点击表格特定单元格时发生。rowid 为行ID；iCol 为列索引；cellcontent 为单元格中内容；e 点击事件对象
	onCellSelect:function(rowid,iCol,cellcontent,e){

		},
	  
}).navGrid('#Path_pager1',{edit:false,add:false,del:false,search: false });
//jQuery("#list1").jqGrid('inlineNav',"#pager1");
	   }
	
function  modifyPath(Path_ID,Order_ID,url){
			$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: "../deliverpathHandle/editDeliverpath.jsp?oper=edit",
   data: encodeURI("Path_ID="+Path_ID+"&Order_ID="+Order_ID+"&"+url),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		$("#Path_list1").trigger("reloadGrid");
		Toalert($(xmlResponse).find('msg').text());
		
		}else{
		Toalert($(xmlResponse).find('msg').text());
		}
 	},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
		}
		
function initreturnInfo(){
		$( "#returnInfo" ).resizable({
			handles: "se"
		});
	$( "#returnGoods-form" ).dialog({
			autoOpen: false,
			height: 500,
			width: 550,
			modal: true,
			buttons: {
				"确认退款": function() {
					var returnGoods_Order_ID=$("#returnGoods_Order_ID").text();
					var returnGoods_User_ID=$("#returnGoods_User_ID").text();
					var returnInfo=$("#returnInfo").val();
					returned_goods(returnGoods_Order_ID,returnGoods_User_ID,returnInfo)
				},
				//"取消": function() {
				//	$( this ).dialog( "close" );
				//}
			},
			"取消": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
	

	}	
	
function sendMsg(url,data){
		$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: url,
   data: encodeURI(data),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		$("#list1").trigger("reloadGrid");
		AddUserMsg($(xmlResponse).find('msg').text());
		
		}else{
		AddUserMsg($(xmlResponse).find('msg').text());
		}
 	},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
	}
// JavaScript Document